import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  {
    // 配置默认路由
    path: "/", // 路由地址
    redirect: "/index", // 重定向
  },
  {
    path: "/index",
    name: "Index",
    component: () => import("../views/Index.vue"),
    redirect: "/foreground",
    children: [
      {
        path: "/foreground",
        name: "Foreground",
        component: () => import("../views/foreground/Index.vue"),
        redirect: "/foreHome",
        children: [
          {
            path: "/foreHome",
            name: "ForeHome",
            component: () => import("../views/foreground/Home.vue"),
          },
          {
            path: "/foreGoods",
            name: "ForeGoods",
            component: () => import("../views/foreground/Goods.vue"),
          },
          {
            path: "/login",
            name: "Login",
            component: () => import("../views/foreground/Login.vue"),
          },
          {
            path: "/register",
            name: "Register",
            component: () => import("../views/foreground/Register.vue"),
          },
          {
            path: "/cart",
            name: "Cart",
            component: () => import("../views/foreground/Cart.vue"),
          },
          {
            path: "/foreComment",
            name: "ForeComment",
            component: () => import("../views/foreground/Comment.vue"),
          },
        ],
      },
      {
        path: "/background",
        name: "Background",
        component: () => import("../views/background/Index.vue"),
        redirect: "/backHome",
        children: [
          {
            path: "/backHome",
            name: "BackHome",
            meta:{
              title:"个人中心",
              super:"/backHome"
            },
            component: () => import("../views/background/Home.vue"),
          },
          {
            path: "/backUser",
            name: "BackUser",
            meta:{
              title:"用户管理",
              super:"/backUser"
            },
            component: () => import("../views/background/User.vue"),
          },
          {
            path: "/backClassify",
            name: "BackClassify",
            meta:{
              title:"分类管理",
              super:"/backGoods"
            },
            component: () => import("../views/background/Classify.vue"),
          },
          {
            path: "/backGoods",
            name: "BackGoods",
            meta:{
              title:"商品管理",
              super:"/backGoods"
            },
            component: () => import("../views/background/Goods.vue"),
          },
          {
            path: "/backOrder",
            name: "BackOrder",
            meta:{
              title:"订单管理",
              super:"/backOrder"
            },
            component: () => import("../views/background/Order.vue"),
          },
          {
            path: "/backComment",
            name: "BackComment",
            meta:{
              title:"留言管理",
              super:"/backComment"
            },
            component: () => import("../views/background/Comment.vue"),
          },
          {
            path: "/backNews",
            name: "BackNews",
            meta:{
              title:"新闻管理",
              super:"/backNews"
            },
            component: () => import("../views/background/News.vue"),
          },
          {
            path: "/backNotice",
            name: "BackNotice",
            meta:{
              title:"公告管理",
              super:"/backNotice"
            },
            component: () => import("../views/background/Notice.vue"),
          },
          {
            path: "/info",
            name: "Info",
            meta:{
              title:"修改资料",
              super:"/info"
            },
            component: () => import("../views/background/Info.vue"),
          },
          {
            path: "/pwd",
            name: "Pwd",
            meta:{
              title:"修改密码",
              super:"/info"
            },
            component: () => import("../views/background/Pwd.vue"),
          },
          {
            path: "/address",
            name: "Address",
            meta:{
              title:"地址管理",
              super:"/info"
            },
            component: () => import("../views/background/Address.vue"),
          },
        ],
      },
    ],
  },
  {
    path: "/:catchAll(.*)",
    name: "404",
    component: () => import("../views/404.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

// router.beforeEach((to, from, next) => {


// });

export default router;
